# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=jboss-autopwn
pkgver=2.986085d
pkgrel=1
groups=('blackarch' 'blackarch-webapp' 'blackarch-exploitation')
pkgdesc='A JBoss script for obtaining remote shell access.'
url="https://github.com/SpiderLabs/jboss-autopwn"
arch=('any')
license=('GPL-3.0-or-later')
depends=('metasploit' 'sbd' 'curl')
makedepends=('git')
source=("git+https://github.com/SpiderLabs/jboss-autopwn.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  sed -i 's/nc/sbd/' *.sh
  sed -i 's|framework3|/usr/share/metasploit|' *.sh
}

package() {
  cd $pkgname

  mkdir -p "$pkgdir/usr/bin/"
  mkdir -p "$pkgdir/usr/share/$pkgname"

  cp -a * "$pkgdir/usr/share/$pkgname"

  cat > "$pkgdir/usr/bin/$pkgname-unix" <<EOF
#!/bin/sh
cd /usr/share/$pkgname/
exec bash ./e.sh "\$@"
EOF
  chmod +x "$pkgdir/usr/bin/$pkgname-unix"

  cat > "$pkgdir/usr/bin/$pkgname-win" <<EOF
#!/bin/sh
cd /usr/share/jboss-autopwn/
exec bash ./e2.sh "\$@"
EOF
  chmod +x "$pkgdir/usr/bin/$pkgname-win"
}

